#pragma once
#include "Singleton.h"
#include <fstream>
#include <iostream>
#include "boost/property_tree/ptree.hpp"
#include "boost/property_tree/ini_parser.hpp"
#include "boost/filesystem.hpp"
#include <map>

struct SectionInfo 
{
    SectionInfo(){}

    ~SectionInfo()
    {
        section_datas_.clear();
    }

    std::map<std::string,std::string> section_datas_;

    std::string operator[](const std::string &key)const
    {
        auto it = section_datas_.find(key);
        if (it!=section_datas_.end())
        {
            return it->second;
        }
        return "";
    }
    //重写拷贝构造
    SectionInfo(const SectionInfo &other)
    {
        section_datas_ = other.section_datas_;
    }
    //重写拷贝赋值
    SectionInfo& operator=(const SectionInfo &other)
    {
        if(this == &other)
        {
            return *this;
        }
        section_datas_ = other.section_datas_;
        return *this;
    }

    //获取值的函数
    std::string GetValue(const std::string &key) const
    {
        auto it = section_datas_.find(key);
        if(it!=section_datas_.end())
        {
            return it->second;
        }
        return "";
    }

};




class ConfigMgr
{
public:
    static ConfigMgr& GetInstance()
    {
        static ConfigMgr instance;
        return instance;
    }

    ~ConfigMgr();
    //拷贝构造
    ConfigMgr(const ConfigMgr &other)
    {
        config_map_ = other.config_map_;
    }
    //重写拷贝赋值
    ConfigMgr& operator=(const ConfigMgr &other)
    {
        if(this == &other)
        {
            return *this;
        }
        config_map_ = other.config_map_;
        return *this;
    }
    //重写[]运算符
    SectionInfo operator[](const std::string &key)
    {
        //判断是否存在该section
        if(config_map_.find(key)==config_map_.end())
        {
            return SectionInfo();
        }
        return config_map_[key];
    }

    std::string GetValue(const std::string &sectionName,const std::string&key);

private:
    ConfigMgr();
    std::map<std::string,SectionInfo> config_map_;
};
